<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>动态绑定class属性</title>
  <script src="../js/vue.js"></script>
  <style>
    .active {
      color: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <h2 class="color"> {{ message }} </h2>
    <h2 :class="color"> {{ message }} </h2>

    <br>
    <!-- 下面单大括号是表示对象 -->
    <!-- <h2 v-bind:class="{key1: value1, ke2: value2} "> {{ message }}</h2> -->
    <!-- title的class不会被覆盖 -->
    <!-- <h1 class="title" v-bind:class="{active: isColor, line: isLine}"> {{ message }} </h1> -->
    <!-- 如果属性过于复杂，可以放在一个methods或者computed中 -->
    <h1 class="title" v-bind:class="getClass()"> {{ message }} </h1>
    <button @click="btnClick">按钮</button>
  </div>

  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        message: '你好啊',
        color: 'active',
        isColor: true,
        isLine: true

      },
      methods: {
        btnClick: function() {
          this.isColor = !this.isColor;
        },
        getClass: function() {
          return  {active: this.isColor, line: this.isLine}
        }
      }
    });
  </script>
</body>

</html>